home *** CD-ROM | disk | FTP | other *** search
/ AppleScript - The Beta Release / AppleScript - The Beta Release.iso / Goodies / Dialog Tinkering / About TinkerDlogInit next >
Text File  |  1992-11-23  |  7KB  |  114 lines

  1. About TinkerDlogInit
  2.  
  3. Here are some tools that let you attach a script to any dialog item in a modal dialog or menu item. This is a proof of concept rather than something that will be available in the system in future. It does let you glimpse into the future when you can attach scripts to every user interface object.
  4.  
  5. TinkerDlogInit should be put in the system extension folder. It patches out GetNewDialog, ModalDialog and other traps. So you may not want to leave it in your system all the time. However, it is in my system for the last half years without any ill effect. Also once tinkering occurs, it connects to the scripting component until the application quits and this may take up a lot of room in your system heap. Tinker Dialog OSAX tells the scripting system about the tinkering terminology and it should be in the scripting additions folder. SimpleDialog is just a simple application to try tinkering out before you try to tinker other application.
  6.  
  7. This is not meant for the end user and there is no user interface to the tinkering, so you have to use Toy Surprise or the ResEdit to develop your script and edit the necessary resource. The event and the class and property you can use are all in the aete resource of the OSAX. Here is the terminology as seen from Toy Surprise.
  8.  
  9. dialog suite: 
  10.  
  11. tinker setdata: Same as setdata, just in case some application would not pass setdata event to system handler
  12.     tinker setdata
  13.         To  '****'
  14.  
  15. tinker keystroke: post keystrokes to the event queue
  16.     tinker keystroke  string
  17.  
  18. tinker open: open the dialog by id or by name and then do a modal dialog
  19.     tinker open
  20.     Result:   'shor'
  21.  
  22. tinker getdata: same as getdata just in case application would not pass getdata to system handler
  23.     tinker getdata
  24.         As  'type'
  25.     Result:   '****'
  26.  
  27. getdata: the core getdata event
  28.     getdata
  29.         As  '****'
  30.     Result:   '****'
  31.  
  32. setdata: the core setdata event
  33.     setdata
  34.         To  '****'
  35.  
  36. my application: return psn = kCurrentProcess, not needed in future
  37.     my application
  38.     Result:   'psn '
  39.  
  40. Class application: 
  41. Elements:
  42.     ditl item by numeric index
  43.     dialog by name
  44.     dialog 'ID  '
  45. Properties:
  46.     name  'itxt'
  47.  
  48. Class ditl item: the items in a dialog
  49. Properties:
  50.     rectangle  'qdrt'  (the location of the dialog item)
  51.     visible  boolean  (is the item visible?)
  52.     hilite  boolean  (is the item enabled?)
  53.     name  'itxt'  (title of the button)
  54.     ditlkind  Button/CheckBox/RadioButton/Control/Static Text/Editable Text/Icon/Picture/UserItem  (the kind of dialog item)
  55.     selection  list  (the selection range of the edit item)
  56.  
  57. Class dialog:
  58.  
  59.  
  60. So you can write script that get and set various property of the dialog in object model style. However whose clause is not supported.
  61.  
  62. To do the tinkering, make a script file using TS or ‘scpt’ editor, then copy the 'scpt' resource to the application (must be HLE aware). You can pick your own resource ID. Find the ID of the dialog and the item number(s) of the dialog item you want to tinker with. Let say the Dialog ID is 201, then you create a 'sdlg' resource with ID 201. The 'sdlg' template is included here. In the 'sdlg' resource, for each dialog item you want to attach a script, you can enter the item number, the script type 'scpt' and the resource ID of the script you want to trigger. For menu tinkering you do the same except with 'smnu' resource where the resource id is the menu id and the item number is the menu item number. After that just run the application after launching Gustav and the target application in the script.
  63.  
  64. The dialog you tinker can be system dialog such as standard file or the print dialog. You should be able to put the 'sdlg' and 'scpt' resource in system file and affects all HLE aware application.
  65.  
  66. We have include a simple program call SimpleDialog to try out the tinkering. SimpleDialog does nothing but search for all the ‘DLOG’ resource in itself (so you can put in more dialog of your own) and put the names of the ‘DLOG’ resource on the menu. When you pick the menu item, it just load the dialog and do a ModalDialog. There is also a menu item for you to tinker with. There is a menu item to send an Apple Event to another application. The idea is that you can then send it to a remote application so the the authentication dialog will be invoked and you can try to tinker with it.
  67.  
  68. Here are some of the scripts in SimpleDialog
  69.  
  70. for radio button
  71.  
  72. tell (my application)
  73.     if not ditl item 4 then -- if it is not already on
  74.         set ditl item 4 to true -- turn myself on
  75.         set ditl item 9 to false -- and turn the other radio button off
  76.     end if
  77.     return 0 -- tell tinkering INIT that action is completed
  78. end tell
  79.  
  80. “my application” is an OSAX function. it is only needed in this version to get around some problem to make it more reliable. The tell block is not necessary in future.
  81.  
  82. for opening a dialog from the menu
  83.  
  84. tell (my application)
  85.     tinker open dialog ID 129 -- just do a modal dialog for dialog 129
  86.     return 0
  87. end tell
  88.  
  89. to swap the pictures in the dialog
  90.  
  91. tell (my application)
  92.     copy ditl item 3 to x -- put a PICT into x
  93.     copy ditl item 4 to y -- put a PICT into y
  94.     set ditl item 3 to y -- put PICT from item 4 to 3
  95.     set ditl item 4 to x -- put PICT from item 3 to 4
  96.     return 0
  97. end tell
  98.  
  99. For authentication, replace "password" by your password. Leave the "/3". The "/3" should really be & Enter in future.
  100.  
  101. tell (my application)
  102.     if hilite of ditl item 8 then -- if we have guest log on
  103.         return {8, 1} -- hit the guess radio button and then OK button
  104.     else
  105.         tinker keystroke "password/3" -- type in password, then enter key
  106.         return {}
  107.     end if
  108. end tell
  109.  
  110. This script let you dismiss the authentication dialog with either guest logon or your own password. This script also brings up interesting points about tinkering. You must realize that when you are tinkering a dialog, the application or system may not aware that you are change the state of the various dialog items since it expects that to be done by user action only. Therefore when you want to hit the radio button for guest logon, while 
  111. set ditl item 8 to true would indeed change the guest radio button, the system in this particular case is not aware of it, that is why you need to return {8, 1} so that it is in the hit list. Similarly, if you set the content of the password field, the system is unaware of it and that is why you need to post the keystroke by the tinker keystroke call.
  112.  
  113. Another earlier failure in tinkering is to let the user pick the printer from the print dialog. The printer was indeed selected, but the print dialog routine is not aware of it so it still print with the old printer selection. The default printer switch only occurs after the current print, thus defeating its purpose. This indicates that tinkering can be tricky, require a lot of experimentation. However it can be quite rewarding. For example, you can put the authentication tinkering dialog in the system folder and solve one of the biggest hassle of using remote Apple Events. If you do this, you may want to change the script resource ID to avoid conflict with any other script in the application.
  114.